package com.wanmait.wisdom.manage.controller;

import com.wanmait.wisdom.entity.Complaint;
import com.wanmait.wisdom.manage.service.ManageComplaintService;
import com.wanmait.wisdom.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/manage")
public class ManageComplaintController {
    @Resource
    private ManageComplaintService manageComplaintService;

    @GetMapping("/getComplaintFinishedCount")
    public AjaxResult getComplaintCount(){
        return AjaxResult.success(manageComplaintService.getComplaintFinishedCount());
    }

    @GetMapping("/getComplaintUnFinishedCount")
    public AjaxResult getComplaintUnFinishedCount(){
        return AjaxResult.success(manageComplaintService.getComplaintUnFinishedCount());
    }

    @PostMapping("/selectComplaint")
    public AjaxResult selectComplaint(){
        List<Complaint> complaintList =manageComplaintService.selectAllComplaints();
        System.out.println(complaintList);
        Collections.reverse(complaintList);
        return AjaxResult.success(complaintList);
    }

    @GetMapping("/selectComplaintById")
    public AjaxResult selectComplaintById(Complaint complaint){
//        Complaint complaint1 = manageComplaintService.getById(complaint);
        Complaint complaint1 =  manageComplaintService.selectComplaintById(complaint.getId());
        System.out.println(complaint1);
        return AjaxResult.success(complaint1);
    }

    @PostMapping("/updateComplaint")
    public AjaxResult updateComplaint(@RequestBody Complaint complaint){
        complaint.setProcessingStatus(1);
        return AjaxResult.success(manageComplaintService.updateById(complaint));
    }

    @PostMapping("/searchComplaintByCondition")
    public AjaxResult searchComplaintByCondition(@RequestBody Complaint complaint, Integer pageNum, Date startTime, Date endTime){
        System.out.println(complaint.getProcessingStatus());
        if (pageNum==null){
            pageNum =1;
        }
        return AjaxResult.success(manageComplaintService.searchComplaintByCondition(complaint,pageNum,startTime,endTime,5));
    }
}
